import {IndexedDBTable} from "./IndexedDBTable";

export namespace TableCardList {
    export interface BaseItem extends IndexedDBTable.BaseItem {
        group?: string;
        link: string;
        siteName: string;
        siteIcon: string;
    }

}

export class TableCardList extends IndexedDBTable<TableCardList.BaseItem> {
    public readonly storeName = "card_list";
    private static instance: TableCardList;

    protected constructor(db: IDBDatabase) {
        super(db);
    }

    protected getTableOption(): IDBObjectStoreParameters | undefined {
        return {
            keyPath: "link",
            autoIncrement: true,
        };
    }

    protected install(objectStore: IDBObjectStore) {
        objectStore.createIndex("group", "group", {});
    }

    public static getInstance(db: IDBDatabase, status: IndexedDBTable.TGetStatus = "get"): TableCardList {
        this.instance = new TableCardList(db);
        if (status === "create") {
            this.instance.startInstall();
        }
        return this.instance;
    }
}
